package com.ds.dsfans.shell.util.platform;


import com.ds.dsfans.shell.util.adb.device.Device;
import com.ds.dsfans.shell.util.adb.device.Devices;
import com.ds.dsfans.shell.util.adb.device.Node;

import java.util.List;

/**
 * 〈功能概述〉<br>
 *
 * @className: Douyin
 * @package:
 * @author:
 * @date:
 */
public class Douyin {
    //mumu模拟器
    //1.创建一定数量模拟器
    //2.开启模拟器
    //3.连接模拟器
    //4.设置IP代理
    //5.打开应用
    //6.账号登录
    //7.查询指定博主
    //8.关注博主
    //9.查看视频
    //10.评论


    public static void main(String[] args) throws Exception {
        //连接容器
//        ShellUtil.process("adb connect 127.0.0.1:16384");
//        //打开抖音
//        Thread.sleep(1000);
//        ShellUtil.process("adb -s 127.0.0.1:16384 shell  am  start  -W  com.ss.android.ugc.aweme/com.ss.android.ugc.aweme.splash.SplashActivity");
//        Thread.sleep(60 * 1000);
        List<Device> devices = Devices.getDevices();
        Douyin douyin = new Douyin();
        if (null != devices) {
            Device device = devices.get(0);
            //刚登录第一页

            List<Node> oneSearch = device.findMain().resourceId("com.ss.android.ugc.aweme:id/search_btn").getNodes();
            //第二页
            List<Node> twoSearch = null;
            //第三页
            List<Node> threeSearch = null;
            if (oneSearch != null && oneSearch.size() > 0) {
                oneSearch.get(0).click();
                Thread.sleep(1000);
            } else {
                if (twoSearch != null && twoSearch.size() > 0) {
                    twoSearch = device.findMain().resourceId("com.ss.android.ugc.aweme:id/hhp").getNodes();
                    twoSearch.get(0).click();
                    Thread.sleep(1000);
                } else {
                    device.findMain().resourceId("com.ss.android.ugc.aweme:id/et_search_kw").getNodes();
                    if (threeSearch != null && threeSearch.size() > 0) {
                        threeSearch.get(0).click();
                        Thread.sleep(1000);
                    }
                }
            }

            //清除-输入文本-搜索
            List<Node> clear = device.findMain().resourceId("com.ss.android.ugc.aweme:id/btn_clear").getNodes();
            if (null != clear && clear.size() > 0) {
                clear.get(0).click();
                Thread.sleep(1000);
            }

            //内容
            List<Node> searchText = device.findMain().resourceId("com.ss.android.ugc.aweme:id/et_search_kw").getNodes();
            if (searchText != null && searchText.size() > 0) {
                searchText.get(0).click();
                Thread.sleep(1000);
                device.input("广汽集团冯兴亚");
                //点击查询
                List<Node> searchKey = device.findMain().resourceId("com.ss.android.ugc.aweme:id/z5o").getNodes();
                if (null != searchKey) {
                    searchKey.get(0).click();
                    Thread.sleep(2000);
                }
            }


            //进入视频主页面
            List<Node> gz = device.findMain().className("com.lynx.tasm.behavior.ui.view.UIView").getNodes();
            if (null != gz) {
                gz.get(0).click();
                Thread.sleep(3000);
            }

            //关注
            List<Node> nodes = device.findMain().resourceId("com.ss.android.ugc.aweme:id/r70").getNodes();
            if (null != nodes && nodes.size() > 0) {
                nodes.get(0).click();
            }
            //获取当前页布局
            device.findMain();
        } else { //coze
            System.err.println("未找到设备");
        }

    }


    /*
     * 自动刷视频关注
     * @Author zhangRenHuo
     * @Date 14:15 2020/9/23
     * @param null
     * @return
     */
    private void attention(Device device) throws Exception {
//        Device.DeviceSize size = device.getSize();
//        device.swipe(size.getWidth() - 10, size.getHeigth() / 2, 0, size.getHeigth() / 2);
        Thread.sleep(500);
        List<Node> nodes = device.findMain().resourceId("com.ss.android.ugc.aweme:id/r70").getNodes();
        if (null != nodes && nodes.size() > 0) {
            nodes.get(0).click();
        }
//        device.swipe(10, size.getHeigth() / 2, size.getWidth(), size.getHeigth() / 2);
//        device.swipe(size.getWidth() / 2, size.getHeigth() / 2, size.getWidth() / 2, 0);
    }

}
